home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / create5a / form1.frm (.txt) next >
Encoding:
Visual Basic Form  |  1999-10-08  |  5.5 KB  |  137 lines

  1. VERSION 5.00
  2. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  3. Begin VB.Form Form1 
  4.    Caption         =   "Form1"
  5.    ClientHeight    =   4875
  6.    ClientLeft      =   1785
  7.    ClientTop       =   1455
  8.    ClientWidth     =   5415
  9.    LinkTopic       =   "Form10"
  10.    ScaleHeight     =   4875
  11.    ScaleWidth      =   5415
  12.    Begin VB.TextBox Text1 
  13.       Height          =   285
  14.       Left            =   480
  15.       TabIndex        =   3
  16.       Top             =   120
  17.       Width           =   3735
  18.    End
  19.    Begin VB.CommandButton Command1 
  20.       Caption         =   "Load"
  21.       Height          =   375
  22.       Left            =   4320
  23.       TabIndex        =   2
  24.       Top             =   60
  25.       Width           =   855
  26.    End
  27.    Begin MSComctlLib.TreeView TreeView1 
  28.       Height          =   1935
  29.       Left            =   0
  30.       TabIndex        =   0
  31.       Top             =   480
  32.       Width           =   3015
  33.       _ExtentX        =   5318
  34.       _ExtentY        =   3413
  35.       _Version        =   393217
  36.       Style           =   7
  37.       Appearance      =   1
  38.    End
  39.    Begin VB.Label Label1 
  40.       Caption         =   "File"
  41.       Height          =   255
  42.       Left            =   120
  43.       TabIndex        =   1
  44.       Top             =   120
  45.       Width           =   495
  46.    End
  47. Attribute VB_Name = "Form1"
  48. Attribute VB_GlobalNameSpace = False
  49. Attribute VB_Creatable = False
  50. Attribute VB_PredeclaredId = True
  51. Attribute VB_Exposed = False
  52. Option Explicit
  53. ' Load a TreeView control from a file that uses tabs
  54. ' to show indentation.
  55. Private Sub LoadTreeViewFromFile(ByVal file_name As String, ByVal trv As TreeView)
  56. Dim fnum As Integer
  57. Dim text_line As String
  58. Dim level As Integer
  59. Dim tree_nodes() As Node
  60. Dim num_nodes As Integer
  61.     fnum = FreeFile
  62.     Open file_name For Input As fnum
  63.     TreeView1.Nodes.Clear
  64.     Do While Not EOF(fnum)
  65.         ' Get a line.
  66.         Line Input #fnum, text_line
  67.         ' Find the level of indentation.
  68.         level = 1
  69.         Do While Left$(text_line, 1) = vbTab
  70.             level = level + 1
  71.             text_line = Mid$(text_line, 2)
  72.         Loop
  73.         ' Make room for the new node.
  74.         If level > num_nodes Then
  75.             num_nodes = level
  76.             ReDim Preserve tree_nodes(1 To num_nodes)
  77.         End If
  78.         ' Add the new node.
  79.         If level = 1 Then
  80.             Set tree_nodes(level) = TreeView1.Nodes.Add(, , , text_line)
  81.         Else
  82.             Set tree_nodes(level) = TreeView1.Nodes.Add(tree_nodes(level - 1), tvwChild, , text_line)
  83.             tree_nodes(level).EnsureVisible
  84.         End If
  85.     Loop
  86.     Close fnum
  87. '''Dim i As Integer
  88. '''Dim factory As Node
  89. '''Dim group As Node
  90. '''Dim person As Node
  91. '''    ' Load pictures into the ImageList.
  92. '''    For i = 1 To 6
  93. '''        TreeImages.ListImages.Add , , TreeImage(i).Picture
  94. '''    Next i
  95. '''    ' Attach the TreeView to the ImageList.
  96. '''    OrgTree.ImageList = TreeImages
  97. '''    ' Create some nodes.
  98. '''    Set factory = OrgTree.Nodes.Add(, , "f R & D", "R & D", otFactory, otFactory2)
  99. '''    Set group = OrgTree.Nodes.Add(factory, tvwChild, "g Engineering", "Engineering", otGroup, otGroup2)
  100. '''    Set person = OrgTree.Nodes.Add(group, tvwChild, "p Cameron, Charlie", "Cameron, Charlie", otPerson, otPerson2)
  101. '''    Set person = OrgTree.Nodes.Add(group, tvwChild, "p Davos, Debbie", "Davos, Debbie", otPerson, otPerson2)
  102. '''    person.EnsureVisible
  103. '''    Set group = OrgTree.Nodes.Add(factory, tvwChild, "g Test", "Test", otGroup, otGroup2)
  104. '''    Set person = OrgTree.Nodes.Add(group, tvwChild, "p Able, Andy", "Andy, Able", otPerson, otPerson2)
  105. '''    Set person = OrgTree.Nodes.Add(group, tvwChild, "p Baker, Betty", "Baker, Betty", otPerson, otPerson2)
  106. '''    person.EnsureVisible
  107. '''    Set factory = OrgTree.Nodes.Add(, , "f Sales & Support", "Sales & Support", otFactory, otFactory2)
  108. '''    Set group = OrgTree.Nodes.Add(factory, tvwChild, "g Showroom Sales", "Showroom Sales", otGroup, otGroup2)
  109. '''    Set person = OrgTree.Nodes.Add(group, tvwChild, "p Gaines, Gina", "Gaines, Gina", otPerson, otPerson2)
  110. '''    person.EnsureVisible
  111. '''    Set group = OrgTree.Nodes.Add(factory, tvwChild, "g Field Service", "Field Service", otGroup, otGroup2)
  112. '''    Set person = OrgTree.Nodes.Add(group, tvwChild, "p Helms, Harry", "Helms, Harry", otPerson, otPerson2)
  113. '''    Set person = OrgTree.Nodes.Add(group, tvwChild, "p Ives, Irma", "Ives, Irma", otPerson, otPerson2)
  114. '''    Set person = OrgTree.Nodes.Add(group, tvwChild, "p Jackson, Josh", "Jackson, Josh", otPerson, otPerson2)
  115. '''    person.EnsureVisible
  116. '''    Set group = OrgTree.Nodes.Add(factory, tvwChild, "g Customer Support", "Customer Support", otGroup, otGroup2)
  117. '''    Set person = OrgTree.Nodes.Add(group, tvwChild, "p Klug, Karl", "Klug, Karl", otPerson, otPerson2)
  118. '''    Set person = OrgTree.Nodes.Add(group, tvwChild, "p Landau, Linda", "Landau, Linda", otPerson, otPerson2)
  119. '''    person.EnsureVisible
  120. End Sub
  121. Private Sub Command1_Click()
  122.     LoadTreeViewFromFile Text1.Text, TreeView1
  123. End Sub
  124. Private Sub Form_Load()
  125. Dim file_name As String
  126.     file_name = App.Path
  127.     If Right$(file_name, 1) <> "\" Then file_name = file_name & "\"
  128.     file_name = file_name & "test.txt"
  129.     Text1.Text = file_name
  130. End Sub
  131. Private Sub Form_Resize()
  132. Dim hgt As Single
  133.     hgt = ScaleHeight - TreeView1.Top
  134.     If hgt < 120 Then hgt = 120
  135.     TreeView1.Move 0, TreeView1.Top, ScaleWidth, hgt
  136. End Sub
  137.